# Script takes two args: smalldump and bigdump.
#
# Both dumpfiles should contain cropped output of !dumpheap -stat
# It should be cropped so that there is not prefix and postfix,
# just the rows with MT address, count, size and type name.
#
# Each line of the output is:
# (how-many-times-more-in-bigger-dump, count, size), type-name
# where count and size pertain to the bigger dump

import re, sys

smalldumpfile = sys.argv[1]
bigdumpfile = sys.argv[2]

def readin(filename):
    data = {}
    for line in open(filename):
        match = re.match(r'[^ ]+ +([^ ]+) +([^ ]+) (.*)', line)
        if match is not None:
            data[match.group(3)] = (int(match.group(1)), int(match.group(2)))
    return data

smalldump = readin(smalldumpfile)
bigdump = readin(bigdumpfile)

difference =  {}
for key in bigdump.iterkeys():
    count, size = bigdump[key][0], bigdump[key][1]
    ration = 0.0
    if key in smalldump.keys():
        ratio = bigdump[key][0] / smalldump[key][0]
    difference[key] = (ratio, count, size)

for key, value in sorted(difference.items(), cmp=lambda x, y: cmp(x[1], y[1])):
    print value, key
    
        
